//
//  TiXianViewController.m
//  YDD
//
//  Created by 欧洪飞 on 2017/8/22.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "TiXianViewController.h"
#import "BankCardViewController.h"
#import "PayTypeTableViewCell.h"

#import "YuePayViewController.h"
@interface TiXianViewController (){
    UILabel *lab;
}

@property (weak, nonatomic) IBOutlet UIView *viewCard;
@property (weak, nonatomic) IBOutlet UIImageView *imagesBank;
@property (weak, nonatomic) IBOutlet UILabel *labBank;
@property (weak, nonatomic) IBOutlet UILabel *labCard;

@property (weak, nonatomic) IBOutlet UITextField *text;
@property (weak, nonatomic) IBOutlet UILabel *labSum;
@property (weak, nonatomic) IBOutlet UILabel *labTXprice;


@property (weak, nonatomic) IBOutlet UILabel *daoLable;

- (IBAction)allPriceEvent:(UIButton *)sender;

@property (nonatomic,strong)NSDictionary *dic;

@end

@implementation TiXianViewController

- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self showNav:@"提现"];
    
    _viewCard.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click)];
    [_viewCard addGestureRecognizer:tap];
    
    _labSum.text = [NSString stringWithFormat:@"可提现余额：%@",_price];
    
    [self loadUI];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self initData];
}

- (void)loadUI{
    _imagesBank.hidden = YES;
    _labBank.hidden = YES;
    _labCard.hidden = YES;
    
    lab = [[UILabel alloc] init];
    lab.text = @"请添加银行卡";
    [_viewCard addSubview:lab];
    [lab makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_viewCard.centerX);
        make.centerY.equalTo(_viewCard.centerY);
    }];
    
    
}

//跳转
- (void)click{
    BankCardViewController *card = [[BankCardViewController alloc] init];
    [self.navigationController pushViewController:card animated:YES];
}


- (IBAction)clickTX:(id)sender {
    [self.text resignFirstResponder];
    NSString *priceValue = self.text.text;
    CGFloat a = [_text.text floatValue];
    CGFloat b = [_price floatValue];
    if ([self isNullOrEmpty:priceValue]) {
        [LICGToast showWithText:@"请输入提现金额" bottomOffset:20 duration:5];
        return;
    }
    
    if (a > b) {
        [LICGToast showWithText:@"提现金额不能大于可提现金额"];
        return;
    }
    
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setObject:_text.text forKey:@"money"];
    [parmas setObject:[_dic objectForKey:@"banknumber"] forKey:@"banknumber"];
    YuePayViewController *yue = [[YuePayViewController alloc] init];
    yue.dic = parmas;
    yue.state = @"提现";
    [self presentViewController:yue animated:YES completion:nil];
}


//提现界面信息
- (void)initData{
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    NSString *url = [NSString stringWithFormat:@"%@/App/Usercenter/withdrawShow",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"res:%@",responseObject);
        _dic = [responseObject objectForKey:@"result"];
        NSString *banknumber = [_dic objectForKey:@"banknumber"];
        if (banknumber.length <= 0) {
            _imagesBank.hidden = YES;
            _labBank.hidden = YES;
            _labCard.hidden = YES;
            lab.hidden = NO;
        }else{
            _imagesBank.hidden = NO;
            _labBank.hidden = NO;
            _labCard.hidden = NO;
            lab.hidden = YES;
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)labSumPrice:(id)sender {
    
}

- (IBAction)allPriceEvent:(UIButton *)sender {
    _text.text = _price;
}
@end
